<template>
  <div class="photoinfo-container">
    <h3>{{photoinfo.title}}</h3>
    <p class="sub-title">
      <span>发表时间:{{photoinfo.add_time|dateFomat}}</span>
      <span>点击:{{photoinfo.click}}次</span>
    </p>
    <hr />
    <!--  缩略图 -->
    <div class></div>
    <vue-preview :slides="list"></vue-preview>
    <div class="content" v-html="photoinfo.content"></div>
    <!-- 如果通过绑定之后的话，后面的id可以省略前面的this -->
    <cmt-box :id="id"></cmt-box>
  </div>
</template>
 <script>
import comment from "../subcomponents/comment.vue";
export default {
  data() {
    return {
      id: this.$route.params.id, //从路由中获取到的图片的id,
      photoinfo: {},
      list: []
    };
  },
  created() {
    this.getPhotoInfo();
    this.getThumbs();
  },
  methods: {
    getPhotoInfo() {
      this.$http
        .get("http://www.liulongbin.top:3005/api/getimageInfo/" + this.id)
        .then(result => {
          if (result.body.status == 0) {
            this.photoinfo = result.body.message[0];
            console.log(this.photoinfo);
          }
        });
    },
    getThumbs() {
      this.$http
        .get("http://www.liulongbin.top:3005/api/getthumimages/" + this.id)
        .then(result => {
          if (result.body.status == 0) {
            result.body.message.forEach(item => {
              item.w = 600;
              item.h = 400;
              item.msrc = item.src;
            });
            this.list = result.body.message;
          }
        });
    }
  },
  components: {
    "cmt-box": comment
  }
};
</script>
<style lang="less" >
.photoinfo-container {
  figure {
    margin: 5px 5px;
    width: 100px;
    height: 100px;
    display: inline-block;

    img {
      border: 0;
      width: 100%;
      height: 100%;
    }
  }
  padding: 3px;
  h3 {
    font-size: 15px;
    color: #26a2ff;
    text-align: center;
    margin: 15px 0;
  }
  .sub-title {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
  }
  .content {
    font-size: 12px;
    line-height: 30px;
  }
}

</style>